<?php

/**
 * This file defines the database model for adding department to classes in the database
 */

class Admin_Model_DbTable_Department extends Zend_Db_Table_Abstract {
	
	protected $_name = 'dept';
	
	protected $_dependentTables = array('Admin_Model_DbTable_schooldept');
	
	public function addDept($deptname) {
		
		$data = array (
		'name' => $deptname
		);
		
		$this->insert($data);
	}
	
	/**
	 * This function returns all the departments in the database.
	 */
	public function viewDepts(){
		
	return $this->fetchAll();
		
	}
	
	
	/**
	 * Function: deleteDept
	 * This method deletes a particular department from the database.
	 */
	public function deleteDept($id){
		
		$this->delete('id =' . (int)$id);
	}
	

	/**
	 * Function: Edit a
	 * This function returns a specific department from the database
	 */
	
		public function getDept($id)	{
			$id = (int)$id;
			$row = $this->fetchRow('id = ' . $id);
			if (!$row) {
			throw new Exception("Count not find row $id");
			}
			return $row->toArray();
		}
	/**
	 * Function: UpdateDept
	 * This function updates a department record in the database
	 */
	public function updateDept($id, $deptname){
		
		$data = array (
			'name' => $deptname
		);
		$this->update($data, 'id =' .(int)$id);
	}
	
}